enable_testing()

include(FetchContent)
FetchContent_Declare(
  googletest
  URL https://bgithub.xyz/google/googletest/archive/03597a01ee50ed33e9dfd640b249b4be3799d395.zip
)

#对于 Windows：防止覆盖父项目的编译/链接设置
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
FetchContent_MakeAvailable(googletest)

add_executable(UNITTESTS UnitTests.cpp)

target_link_libraries(UNITTESTS
                    GTest::gtest_main
                    DESIGN_LIB
                    DATA_LIB
                    )

include(GoogleTest)
gtest_discover_tests(UNITTESTS)





# enable_testing()

# # -------------------- 配置本地预编译的Google Test --------------------
# # 设置本地gtest路径
# set(GTEST_ROOT ${CMAKE_SOURCE_DIR}/3rd/googletest-1.11.0)

# # 设置头文件路径
# set(GTEST_INCLUDE_DIR ${GTEST_ROOT}/include)
# set(GTEST_LIBRARY_DIR ${GTEST_ROOT}/lib)

# # 查找静态库文件（假设库文件名为gtest.lib和gtest_main.lib）
# find_library(GTEST_LIBRARY
#     NAMES gtest gtestd
#     PATHS ${GTEST_LIBRARY_DIR}
#     REQUIRED
#     NO_DEFAULT_PATH
# )

# find_library(GTEST_MAIN_LIBRARY
#     NAMES gtest_main gtest_maind
#     PATHS ${GTEST_LIBRARY_DIR}
#     REQUIRED
#     NO_DEFAULT_PATH
# )

# # 定义导入目标
# add_library(GTest::gtest STATIC IMPORTED)
# add_library(GTest::gtest_main STATIC IMPORTED)

# # 设置目标属性（静态库路径和头文件目录）
# set_target_properties(GTest::gtest PROPERTIES
#     IMPORTED_LOCATION ${GTEST_LIBRARY}
#     INTERFACE_INCLUDE_DIRECTORIES ${GTEST_INCLUDE_DIR}
# )

# set_target_properties(GTest::gtest_main PROPERTIES
#     IMPORTED_LOCATION ${GTEST_MAIN_LIBRARY}
#     INTERFACE_INCLUDE_DIRECTORIES ${GTEST_INCLUDE_DIR}
# )

# # -------------------- 定义单元测试可执行文件 --------------------
# add_executable(UNITTESTS UnitTests.cpp)

# # 设置头文件目录
# target_include_directories(UNITTESTS
#     PRIVATE
#     ${GTEST_INCLUDE_DIR}
# )

# # 链接依赖库
# target_link_libraries(UNITTESTS
#     PRIVATE
#     GTest::gtest_main
#     GTest::gtest
#     DESIGN_LIB
# )

# # 自动复制DLL到输出目录
# # 根据构建类型选择DLL名称和库路径
# if (CMAKE_BUILD_TYPE STREQUAL "Debug")
#     set(GTEST_DLL_NAME "gtestd.dll")
# else()
#     set(GTEST_DLL_NAME "gtest.dll")
# endif()

# add_custom_command(TARGET UNITTESTS POST_BUILD
#     COMMAND ${CMAKE_COMMAND} -E copy_if_different
#         "${GTEST_ROOT}/bin/${GTEST_DLL_NAME}"
#         $<TARGET_FILE_DIR:UNITTESTS>
#     COMMENT "Copying Google Test DLLs (${GTEST_DLL_NAME})..."
# )

# # 自动发现测试
# include(GoogleTest)
# gtest_discover_tests(UNITTESTS)